package cn.com.elite;
import ins.platform.interf.utils.InterfaceServletInvoker;
import ins.platform.message.vo.SmsVo;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class SmsImplTest {
	private static final Log log=LogFactory.getLog(SmsImplTest.class);

	/**
	 * @param args
	 * @throws IOException 
	 * @throws IOException 
	 */
	
	public String SendSms(String url,String requestType,String user,String password,String fromnum,String tonum,String content,String businesstype,String systemcode,String documentout_guid) throws IOException{
		log.info("url:"+url);
		log.info("requestType:"+requestType);
		log.info("password:"+password);
		log.info("fromnum:"+fromnum);
		log.info("tonum:"+tonum);
		log.info("content:"+content);
		log.info("businesstype:"+businesstype);
		log.info("systemcode:"+systemcode);
		log.info("documentout_guid:"+documentout_guid);
		String inXmlBody = "";
		String outXmlBody = "";
		InterfaceServletInvoker interfaceInvoker2=new InterfaceServletInvoker(url);
		SmsVo smsVo = new SmsVo();
		smsVo.setFromNumber(fromnum);
		smsVo.setUuid(documentout_guid);
		smsVo.setToNumber(tonum);
		smsVo.setNation(new BigDecimal(86));
		smsVo.setBusinessType(businesstype);
		smsVo.setSystemCode(systemcode);
		smsVo.setSendTime(null);
		Calendar cal = Calendar.getInstance();
		java.util.Date sendTime = cal.getTime();
		smsVo.setContent(content);
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("Request", SmsVo.class);
		inXmlBody = xstream.toXML(smsVo);
		log.info("==============输入XML================");
		log.info(inXmlBody);
		log.info("====================================");
		outXmlBody = interfaceInvoker2.request(requestType,user,password,inXmlBody,"utf-8");			
		log.info("==============输出XML================");
		log.info(outXmlBody);
		log.info("====================================");	
		return outXmlBody;
	}
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
//		String url = "http://localhost:8080/messageweb/interface"; 
		String url = "http://109.101.85.5:7012/messageweb/interface";
		String inXmlBody = "";
		String outXmlBody = "";
		String requestType = "002";
		String user = "0000000000";
		String password = "pcpcncdi";
//		String xmlBody = "";
////		传送xmlBody
//		xmlBody += "<Request>";
//		xmlBody += "<username>demo</username>";
//		xmlBody += "<password>demo</password>"; 
//		xmlBody += "</Request>";
//		InterfaceServletInvoker interfaceInvoker1=new InterfaceServletInvoker(url);
//		outXmlBody = interfaceInvoker1.request(requestType, user, password, xmlBody);
//		System.out.println("===============输入xml===============");
//		System.out.println(outXmlBody);
//		System.out.println("====================================");
//		 传送DTO
		InterfaceServletInvoker interfaceInvoker2=new InterfaceServletInvoker(url);
		SmsVo smsVo = new SmsVo();
		smsVo.setFromNumber("13636445902");
		smsVo.setUuid(UUID.randomUUID().toString());
		smsVo.setToNumber("13636445902");
		smsVo.setNation(new BigDecimal(86));
		Calendar cal = Calendar.getInstance();
		java.util.Date sendTime = cal.getTime();
//		smsVo.setSendTime(sendTime);
		smsVo.setContent("测试短信  20111130ewwwwwwwwwwwwwwweeeeeee那拉萨市看童子良 成功！！！");
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("Request", SmsVo.class);
		inXmlBody = xstream.toXML(smsVo);
		System.out.println("==============输入XML================");
		System.out.println(inXmlBody);
		System.out.println("====================================");
		outXmlBody = interfaceInvoker2.request(requestType, user, password, inXmlBody,"utf-8");			
		System.out.println("==============输出XML================");
		System.out.println(outXmlBody);
		System.out.println("====================================");	
	}

}
